<?php
require_once '../sub/init.php';
require_once 'chkUadm.php';
if($session_kind == 'crm'){
	if(!in_array('crm_user_mod',$QXARR) && !in_array('crm_user_mod_my',$QXARR) )exit(noauth());
}else{
	if(!in_array('u_mod',$QXARR))exit(noauth('暂无【资料修改】权限'));
}
header("Cache-control: private");
require_once ZEAI.'cache/config_up.php';
require_once ZEAI.'sub/zeai_up_func.php';
require_once ZEAI.'sub/ZeaiUP.php';
if ($submitok == "ajax_user_chkmob") {
	$mob=trimhtml($mob);
	if (!ifmob($mob))json_exit(array('flag'=>0,'msg'=>'请输入【手机号码】'));
	if (!ifmob($mob2) && !empty($mob2))json_exit(array('flag'=>0,'msg'=>'请输入【备用手机号码】'));
	
	$row = $db->ROW(__TBL_USER__,"id","mob='".$mob."' OR mob2='".$mob."'","name");
	if ($row)json_exit(array('flag'=>0,'msg'=>'【'.$mob.'】手机已被【UID：'.$row['id'].'】占用，请重新输入'));
	
	if(!empty($mob2)){
		if (!ifmob($mob2))json_exit(array('flag'=>0,'msg'=>'请输入正确的【备用手机号码】'));
		$row = $db->ROW(__TBL_USER__,"id","mob='".$mob2."' OR mob2='".$mob2."'","name");
		if ($row)json_exit(array('flag'=>0,'msg'=>'【'.$mob2.'】手机已被【UID：'.$row['id'].'】占用，请重新输入'));
	}
	json_exit(array('flag'=>1,'msg'=>'OK'));
}elseif($submitok == "ajax_user_chksfz") {
	if(!empty($sfz)){
		$row = $db->ROW(__TBL_USER__,"id","identitynum='".$sfz."' AND identitynum<>''","name");
		if ($row)json_exit(array('flag'=>0,'msg'=>'【'.$sfz.'】身份证号已被【UID：'.$row['id'].'】占用，请重新输入'));
	}
	json_exit(array('flag'=>1));
}elseif($submitok == "addupdate") {
	if (str_len($uname) > 20 || str_len($uname)<3)alert("请输入正确的用户名",-1);
	if (str_len($pwd) > 20 || str_len($pwd)<6)alert("请输入正确的密码",-1);
	if (!ifint($kind))alert("请输入选择用户类型",-1);
	$mob=trimhtml($mob);
	$mob2=trimhtml($mob2);
	if (!ifmob($mob))alert('请输入【手机号码】');
	if (!ifmob($mob2) && !empty($mob2))alert('请输入【备用手机号码】');
	$row = $db->ROW(__TBL_USER__,"id","mob='".$mob."' OR mob2='".$mob."'","name");
	if ($row)alert('手机已被【UID：'.$row['id'].'】占用，请重新输入',-1);
	if(!empty($mob2)){
		$row = $db->ROW(__TBL_USER__,"id","mob='".$mob2."' OR mob2='".$mob2."'","name");
		if ($row)alert('【'.$mob2.'】手机已被【UID：'.$row['id'].'】占用，请重新输入');
	}
	$sex = (empty($sex))?1:intval($sex);
	$uname    = dataIO($uname,'in');
	$nickname = trimhtml(dataIO($nickname,'in',40));
	$truename = trimhtml(dataIO($truename,'in',12));
	$identitynum = trimhtml(dataIO($identitynum,'in',18));
	if(!empty($identitynum)){
		$row = $db->ROW(__TBL_USER__,"id","identitynum='".$identitynum."' AND identitynum<>''","name");
		if ($row)alert('【'.$identitynum.'】身份证号已被【UID：'.$row['id'].'】占用，请重新输入',-1);
	}
	$pwd      = md5(trim($pwd));
	$kind = intval($kind);
	$birthday = (!ifdate($birthday))?'0000-00-00':$birthday;
	$flag     = ($flag==1)?1:-2;
	$dataflag = 1;
	if(!empty($agentid_admid)){
		$agentid_admid = explode(',',$agentid_admid);
		$agentid = intval($agentid_admid[0]);
		$admid   = intval($agentid_admid[1]);
	}
	$SETSQL = "";
	if(ifint($agentid)){
		$row3 = $db->ROW(__TBL_CRM_AGENT__,"title","id=".$agentid,"num");
		if ($row3)$SETSQL .= ",agentid=$agentid,agenttitle='".$row3[0]."'";
	}else{$SETSQL .= ",agentid=0,agenttitle=''";}
	if($admid>0){
		$row3 = $db->ROW(__TBL_CRM_HN__,"truename","id=".$admid,"num");
		if ($row3)$SETSQL .= ",admid=$admid,admtime=".ADDTIME.",admname='".$row3[0]."'";
	}else{$SETSQL .= ",admid=0,admname=''";}
	if($ifmobrz==1)$SETSQL .= ",RZ='mob'";
	$crm_ukind = intval($crm_ukind);
	$crm_fromclue = intval($crm_fromclue);
	$db->query("INSERT INTO ".__TBL_USER__." (kind,uname,nickname,pwd,regtime,endtime,refresh_time,regkind,sex,birthday,flag,crm_ukind,crm_fromclue,mob,mob2,truename,identitynum) VALUES ($kind,'".$uname."','".$nickname."','".$pwd."',".ADDTIME.",".ADDTIME.",".ADDTIME.",9,$sex,'".$birthday."',$flag,$crm_ukind,$crm_fromclue,'$mob','$mob2','$truename','$identitynum')");
	$uid = intval($db->insert_id());
	$db->query("UPDATE ".__TBL_USER__." SET dataflag='$dataflag'".$SETSQL." WHERE id=".$uid);
	shalou_init($uid);
	//
	$row_shalou=shalou_data($uid);
	$row_shalou['truename']=$truename;
	$row_shalou['identitynum']=$identitynum;
	$new_row_shalou=encode_json($row_shalou);
	$db->query("UPDATE ".__TBL_SHALOU__." SET jsonstr='$new_row_shalou' WHERE uid=".$uid);
	//
	sea_mod_time($uid);
	set_data_ed_bfb($uid);
	AddLog('录入新用户【'.$nickname.'（uid:'.$uid.'）】');
	//alert("录入成功，请继续完善资料".$cc,"");
	header("Location: m_u_mod.php?submitok=mod&t=".$t."&uid=".$uid);
	
}elseif($submitok == "submitCut_success") {
	//上传裁切新头像处理
	if(!empty($_cut)){
		$SHALOU_ARR=shalou_data($uid);
		$shalou_photo_s = $SHALOU_ARR['photo_s'];
		$_s = cut_save('adm',$_cut,'all');
			//$db->query("UPDATE ".__TBL_USER__." SET photo_s='".$_s."',photo_f=1 WHERE id=".$uid);
			//$db->query("UPDATE ".__TBL_SHALOU__." SET photo_f=1 WHERE uid=".$uid);
			//set_data_ed_bfb($uid);
		$SHALOU_ARR['photo_s']=$_s;
		$jsonstr = encode_json($SHALOU_ARR);
		$db->query("UPDATE ".__TBL_SHALOU__." SET jsonstr='$jsonstr',addtime=".ADDTIME." WHERE uid=".$uid);
		//删老
		$row = $db->ROW(__TBL_USER__,"photo_s","id=".$uid,"num");
		$data_photo_s = $row[0];
		if(!empty($data_photo_s) && $shalou_photo_s!=$data_photo_s){
			UP_modFn('adm','del',$shalou_photo_s.'|'.smb($shalou_photo_s,'m').'|'.smb($shalou_photo_s,'b').'|'.smb($shalou_photo_s,'blur'));
		}
		json_exit(array('flag'=>1,'msg'=>'裁切成功'));
	}else{
		json_exit(array('flag'=>0,'msg'=>'上传裁切更新失败'));
	}
}elseif($submitok == "modupdate") {
	if(ifint($uid)){
		$row = $db->ROW(__TBL_USER__,"weixin_pic,photo_s","id=".$uid);
		if (!$row)json_exit(array('flag'=>0,'msg'=>'用户不存在'));
		$data_weixin_pic= $row['weixin_pic'];
		$data_photo_s= $row['photo_s'];
	}else{
		json_exit(array('flag'=>0,'msg'=>'用户不存在'));
	}
	$FARR = $_POST;
	unset($FARR['submitok']);unset($FARR['js']);unset($FARR['uid']);unset($FARR['photo_s']);unset($FARR['weixin_pic']);unset($FARR['t']);
	if (count($FARR) >= 1 && is_array($FARR)){
		$newARR=array();
		$mate_diy = explode(',',$_ZEAI['mate_diy']);
		foreach ($FARR as $k=>$V) {
			if(strstr($k,'form_mate_')){
				$k2=str_replace('form_mate_','mate_',$k);
				$newARR[$k2]=$V;
			}else{
				$newARR[$k]=$V;
			}
		}
		$SHALOU_ROW=shalou_data($uid,'all');
		$SHALOU_ARR=(!empty($SHALOU_ROW))?json_decode($SHALOU_ROW['jsonstr'],true):'';
		$SQLli="";
		foreach ($newARR as $F=>$V) {
			switch ($F) {
				case 'aboutus':
					$V = dataIO(trimhtml($V,'keep_rn'),'in',2000);
				break;
				case 'nickname':
					$V = dataIO($V,'in',50);
				break;
				default:
					$V = dataIO($V,'in',200);
				break;
			}
			if(strstr($F,'mate_')){
				$ext = mate_diy_par(str_replace("mate_","",$F),'ext');
				if($ext=='radiorange'){
					$Varr=explode(',',$V);
					$mate_form1=$Varr[0];$mate_form2=$Varr[1];
					$SHALOU_ARR[$F.'1']=$mate_form1;
					$SHALOU_ARR[$F.'2']=$mate_form2;
					$SQLli.=",".$F.'1'."='".$mate_form1."'";
					$SQLli.=",".$F.'2'."='".$mate_form2."'";
				}else{
					if(!empty($V))$SHALOU_ARR[$F]=$V;
					$SQLli.=",".$F."='".$V."'";
				}
			}else{
				if(!empty($V))$SHALOU_ARR[$F]=$V;
				if($F!='photo_s' && $F!='weixin_pic' && !empty($V) )$SQLli.=",".$F."='".$V."'";
			}
		}
		//新头像处理
		if(!empty($photo_s)){
			if(strrpos($photo_s,'/tmp/')){
				$_s = cut_save('adm',$photo_s,'all');
			}else{
				$_s = $photo_s;
			}
			$db->query("UPDATE ".__TBL_USER__." SET photo_s='".$_s."',photo_f=1 WHERE id=".$uid);
			$db->query("UPDATE ".__TBL_SHALOU__." SET photo_f=1 WHERE uid=".$uid);
			set_data_ed_bfb($uid);
			$SHALOU_ARR['photo_s']=$_s;
			//删老
			if(!empty($data_photo_s) && $data_photo_s!=$photo_s){
				UP_modFn('adm','del',$data_photo_s.'|'.smb($data_photo_s,'m').'|'.smb($data_photo_s,'b').'|'.smb($data_photo_s,'blur'));
			}
		}
		//新微信图片
		if(!empty($weixin_pic) && strrpos($weixin_pic,'/tmp/')){
			if(!empty($data_weixin_pic) && $data_weixin_pic!=$weixin_pic)@UP_modFn('adm','del',$data_weixin_pic);
			$_s=@UP_modFn('adm','tmp_p',$weixin_pic,'weixin');
			$db->query("UPDATE ".__TBL_USER__." SET weixin_pic='$_s' WHERE id=".$uid);
			set_data_ed_bfb($uid);
			$SHALOU_ARR['weixin_pic']=$_s;
		}
		$mate_other=dataIO($form_mate_other,'in');
		$db->query("UPDATE ".__TBL_USER__." SET dataflag=1".$SQLli.",mate_other='$mate_other' WHERE id=".$uid);
		set_data_ed_bfb($uid);
		Dmod($uid,encode_json($SHALOU_ARR));
		AddLog('修改完善用户【'.$SHALOU_ARR['nickname'].'（uid:'.$uid.'）】用户资料');
	}
	json_exit(array('flag'=>1,'msg'=>'保存成功'));
}
require_once ZEAI.'cache/udata.php';
require_once ZEAI.'cache/config_up.php';
require_once ZEAI.'sub/zeai_up_func.php';
require_once ZEAI.'sub/ZeaiUP.php';
$FA=udata_arr('all','userF');
$currfields_sl=$FA.',areatitle,area2title,'.get_mate_fld('list');
if($submitok=='add'){
	$nav='m_u_add';
	$submitok_str='录入';
	$top_btn_save_str = '下一步';
}else{
	if(ifint($uid)){
		$row = $db->ROW(__TBL_USER__,"mate_other","id=".$uid);
		if (!$row)alert('用户不存在','-1');
		$mate_other=dataIO($row['mate_other'],'out');
	}else{
		alert('用户不存在','-1');
	}
	$nav='m_u';
	$submitok_str='修改';
	$top_btn_save_str = '保存';
	
	$SHALOU_ROW=shalou_data($uid,'all');
	$photo_f_sl=$SHALOU_ROW['photo_f'];
	$SHALOU_ARR=(!empty($SHALOU_ROW))?json_decode($SHALOU_ROW['jsonstr'],true):'';

	if (!empty($SHALOU_ARR) && @count($SHALOU_ARR)>0){
		//$cook_sex      = $SHALOU_ARR['sex'];
		  //$cook_photo_s  = $SHALOU_ARR['photo_s'];
		//$cook_weixin_pic= $SHALOU_ARR['weixin_pic'];
		///$cook_nickname = trimhtml(dataIO($SHALOU_ARR['nickname'],'out'));
		//$cook_myinfobfb= get_shalou_ed_bfb($SHALOU_ARR);
	}elseif(ifint($uid)){
		$row = $db->ROW(__TBL_USER__,$currfields_sl,"id=".$uid,"name");
		$jsonstr=encode_json($row);
		$db->query("INSERT INTO ".__TBL_SHALOU__." (uid,jsonstr,addtime) VALUES ($uid,'$jsonstr',".ADDTIME.")");
		header("Location: m_u_mod.php?uid=$uid");exit;
	}
}
?>
<!doctype html><html><head><meta charset="utf-8">
<title><?php echo $_ADM['admSiteName']; ?></title>
<?php echo HEADMETA; ?>
<script src="<?php echo RES;?>www_zeai_cn.js?<?php echo $_ZEAI['cache_str'];?>"></script>
<script src="<?php echo RES;?>m/js/m.js?<?php echo $_ZEAI['cache_str'];?>"></script>
<script>
var upurl='<?php echo SELF;?>',upMaxMB = <?php echo $_UP['upMaxMB']; ?>,browser='<?php echo browser();?>',up2='<?php echo $_ZEAI['up2'];?>/',Sbindbox = 'ZEAI_CN__FORM',maxnum=1;
</script>
<script src="<?php echo RES;?>m/js/ZeaiUP.js?<?php echo $_ZEAI['cache_str'];?>"></script>
<script src="<?php echo HOST;?>/cache/udata.js?<?php echo $_ZEAI['cache_str'];?>"></script>
<script src="<?php echo RES;?>zeai_ios_select/separate/select.js?<?php echo $_ZEAI['cache_str'];?>"></script>
<script src="<?php echo RES;?>m/js/birthday.js?<?php echo $_ZEAI['cache_str'];?>"></script>
<script src="<?php echo HOST;?>/cache/areadata.js?<?php echo $_ZEAI['cache_str'];?>"></script>
<script src="<?php echo RES;?>m/js/zeai_div_area.js?<?php echo $_ZEAI['cache_str'];?>"></script>
<script src="js/m_u_mod.js?<?php echo $_ZEAI['cache_str'];?>"></script>
<link href="<?php echo RES;?>m/css/m.css?<?php echo $_ZEAI['cache_str'];?>" rel="stylesheet" type="text/css" />
<link href="css/m_adm.css?<?php echo $_ZEAI['cache_str'];?>" rel="stylesheet" type="text/css" />
<?php
if (is_weixin()){
	require_once ZEAI."api/weixin/jssdk.php";?>
	<script src="<?php echo RES;?>jweixin-1.2.0.js"></script>
	<script>
	wx.config({debug: false,
		appId: '<?php echo $signPackage["appId"];?>',
		timestamp: <?php echo $signPackage["timestamp"];?>,
		nonceStr: '<?php echo $signPackage["nonceStr"];?>',
		signature: '<?php echo $signPackage["signature"];?>',
		jsApiList: ['chooseImage','uploadImage','previewImage','hideMenuItems']
	});
	</script>
<?php }?>
<style>
html,body{min-height:100%;width:100%;}
.size4{background-color:<?php echo $_ADM['color'];?>}
#top_btn_save{position:fixed;top:8px;right:15px;padding:0 12px;line-height:34px;border-radius:2px;color:#fff;font-size:16px;background-color:<?php echo $_ADM['color'];?>;z-index:3}

.listbox{width:100%;margin-bottom:15px;margin-top:50px;border-top:#f5f5f5 10px solid}
.listbox dl.other dt{width:65%;}
.listbox dl.other dd{width:35%;}
.listbox dl{width:100%;box-sizing:border-box;padding:0 5%;margin:0 auto;height:50px}
.listbox dl.dl1{border-top:#f5f5f5 12px solid;height:73px}
.listbox dl.dl0{border-bottom:#f5f5f5 12px solid;height:73px}
.listbox dl.dl0 dt,.listbox .dl0 dd{border:0}
.listbox dl dt,.listbox dl dd{font-size:14px;line-height:50px;height:50px;border-bottom:#f2f2f2 1px solid}
.listbox dl dt{width:32%;float:left;text-align:left}
.listbox dl dd{width:68%;float:right;text-align:right;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;position:relative}
.listbox dl dd span{color:#999}
.listbox dl dd span.ed{color:#333}
.listbox dl dd span font.tips,.listbox dl dd span font.photo0tips{font-size:12px;position:absolute;right:35px;top:16px;line-height:20px;border-radius:10px 10px 0 10px;padding:0 5px;}
.listbox dl dd span i{font-size:12px;color:#ccc}
.listbox .input,.listbox .select{border:0;float:right;line-height:30px;height:30px;text-align:right;margin-top:10px}
.listbox .select{color:#aaa;direction:rtl}
.listbox .selected{color:#333}
.listbox .input{width:95%}
.listbox dl.dlpic dd img{width:40px;height:40px;object-fit:cover;-webkit-object-fit:cover;border-radius:3px;margin-top:5px}
.listbox dl.dlpic dd i.ico{font-size:30px;vertical-align:middle}
.listbox dl.dlpic dd font{display:inline-block;vertical-align:middle;margin-left:5px}
.listbox dl.dlpic dd font.photo0tips{right:50px}
.listbox .tbody{line-height:50px;background-color:#f5f5f5;font-size:15px;font-weight:bold}

.areabox .ul li a{position:relative;color:#666;background-color:#f7f7f7;height:30px;line-height:30px;margin:5px 5px;overflow:hidden;box-sizing:border-box;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;border:0;padding:0 8px}
.areabox .ul li a:hover:before,.areabox .ul li a.ed:before{position:absolute;font-family:"www_zeai_cn_iconfont" !important;content:"\e64a";width:15px;height:15px;line-height:15px;font-size:16px;right:0;bottom:0}
.areabox .ul li a.ed{border-radius:3px 3px 0 3px}
.areabox .ul dt.ed{border-top-color:<?php echo $_ADM['color'];?>;color:<?php echo $_ADM['color'];?>}
.areabox .ul li a.ed{background-color:<?php echo $_ADM['color'];?>;}
.listbox .ios-select-widget-box header.iosselect-header{height:51px;line-height:44px;background:#fff}
.listbox .ios-select-widget-box.olay {background-color:rgba(0,0,0,.6);z-index:890}
.listbox .ios-select-widget-box.olay > div {width:100%;top:auto;bottom:0;left:0;border-radius:0;padding-bottom:58px;background-color:#fff;}
.listbox .ios-select-widget-box.olay > div h2{font-size:16px;text-align:left;float:left;padding-left:3%;}
.listbox .ios-select-widget-box header.iosselect-header a.sure {margin: 8px 10px 0 0;}
.listbox .iosselect-header{display:block}
.listbox .ios-select-widget-box .cover-area1 {top:157px}
.listbox .ios-select-widget-box .cover-area2 {top:191px}
.divBtmMod .form ul.RCW li{width:50%}
.mask1{background-color:rgba(0,0,0,.6)}
.blank{height:120px}
.select,.input,.textarea{font-size:14px}
.ios-select-widget-box header.iosselect-header a.sure,.divBtmMod .divBtmSave,.checkskin:checked + label.checkskin-label i{background-color:<?php echo $_ADM['color'];?>;border-radius:2px}
.checkskin:checked + label.checkskin-label i{border-color:<?php echo $_ADM['color'];?>;}

.mob_box em{width:90%;margin:10px auto;text-align:left}
.mob_box em b{font-weight:normal;margin-right:12px}
.mob_box em .input2{width:70%;padding-left:8px}
.mob_box .size4{margin-top:0px}

</style>
</head>
<body>
<?php 
$mt=($t=='crm')?'客户':'用户';
$mini_title=$mt.$submitok_str;
if($submitok != 'add')$mini_title.='-UID:'.$uid.'';
$mini_class='top_mini4';
require_once ZEAI.'m/top_mini.php';?>
<a id="top_btn_save"><?php echo $top_btn_save_str;?></a>
<form class="listbox" id="ZEAI_CN__FORM">
<!--ADD-->
<?php
if ($submitok=='add'){?>
    <div id="step1">
        <dl id="mob" class="mob"><dt>手机号码 <b class="Cf00">*</b></dt><dd><span><i class="ico">&#xe601;</i></span></dd></dl>
        <div id="mob_box" class="btmboxinput mob_box">
            <h2>用户手机</h2>
            <em>
            <b>手机号码</b><input type="text" name="mob" id="form_mob" class="input2 W200" pattern="[0-9]*" placeholder="输入手机号码(必填)" maxlength="11" onBlur="zeai.setScrollTop(0);" autocomplete="off" ><br>
            <b>认证状态</b><input type="checkbox" name="ifmobrz" id="form_ifmobrz" class="checkskin" value="1" checked><label for="form_ifmobrz" class="checkskin-label"><i></i><b class="S12 W100 S14">点亮认证图标</b></label><br><br>
            <b>备用手机</b><input type="text" name="mob2" id="form_mob2" class="input2 W200" pattern="[0-9]*" placeholder="输入备用手机号码" maxlength="11" onBlur="zeai.setScrollTop(0);" autocomplete="off" >
            </em>
            <button type="button" class="btn size4" id="mob_box_btn">确定</button>
        </div>
        <dl id="sex" class="slect"><dt>性　　别 <b class="Cf00">*</b></dt><dd><span><i class="ico">&#xe601;</i></span></dd></dl><input type="hidden" id="form_sex" name="sex">
        <dl id="birthday" class="bthdy" data="<?php echo YmdHis(ADDTIME-788400000,'Ymd');?>"><dt>生　　日 <b class="Cf00">*</b></dt><dd><span><i class="ico">&#xe601;</i></span></dd></dl><input type="hidden" id="form_birthday" name="birthday">

        <dl id="truename" class="ipt"><dt>真实姓名</dt><dd><span><i class="ico">&#xe601;</i></span></dd></dl><input type="hidden" id="form_truename" name="truename">
        <dl id="identitynum" class="ipt"><dt>身份证号</dt><dd><span><i class="ico">&#xe601;</i></span></dd></dl><input type="hidden" id="form_identitynum" name="identitynum">
        <dl id="nickname" class="dl0 ipt"><dt>昵称网名 <b class="Cf00">*</b></dt><dd><span><i class="ico">&#xe601;</i></span></dd></dl><input type="hidden" id="form_nickname" name="nickname">
        <?php
        $rt=$db->query("SELECT id,title FROM ".__TBL_CRM_AGENT__." WHERE flag=1 ORDER BY px DESC,id DESC");
        $total = $db->num_rows($rt);
        if ($total > 0) {
            $arr1[] = array('i'=>'ze','v'=>'公海资源','f'=>'0');
            $arr2[] = array('i'=>'ai','v'=>'--','f'=>'ze');
            for($i=0;$i<$total;$i++) {
                $rows = $db->fetch_array($rt,'name');
                if(!$rows) break;
                $rt2=$db->query("SELECT id,truename,username FROM ".__TBL_CRM_HN__." WHERE agentid=".$rows['id']." AND kind='crm' AND flag=1 ORDER BY px DESC,id DESC");
                $total2 = $db->num_rows($rt2);
                if ($total2 > 0) {
                    for($i2=1;$i2<=$total2;$i2++) {
                        $rows2 = $db->fetch_array($rt2,'name');
                        if(!$rows2)break;
                        $arr2[] = array('i'=>$rows2['id'],'v'=>$rows2['truename'].'(ID:'.$rows2['id'].')','f'=>$rows['id']);
                    }
                }else{
                    $arr2[] = array('i'=>cdstrletters(5),'v'=>'--','f'=>$rows['id']);
                }
                $arr1[] = array('i'=>$rows['id'],'v'=>$rows['title'],'f'=>'0');
            }
            $agentid_admid_ARR1 = encode_json($arr1);
            $agentid_admid_ARR2 = encode_json($arr2);
            $defstr = (ifint($session_agentid) && ifint($session_uid))?$session_agentid.','.$session_uid:'<i class="ico">&#xe601;</i>';
            if(ifint($session_agentid) && ifint($session_uid) && $session_kind=='crm'){
                $def_data = $session_agentid.','.$session_uid;
                $def_str  = $session_agenttitle.' '.$session_truename.'(id:'.$session_uid.')';
            }else{
                $def_data = '';
                $def_str  = '<i class="ico">&#xe601;</i>';
            }
            ?>
            <dl id="agentid_admid" class="slect2" data="<?php echo $def_data;?>"><dt>用户归属</dt><dd><span><?php echo $def_str;?></span></dd></dl>
            <input type="hidden" id="form_agentid_admid" name="agentid_admid" value="<?php echo $def_data;?>">
            <script>var agentid_admid_ARR1 = <?php echo $agentid_admid_ARR1;?>,agentid_admid_ARR2 = <?php echo $agentid_admid_ARR2;?>;</script>
            <?php
        }
        ?>
        <script>var kind_ARR=[{i:"1",v:"线上用户"},{i:"2",v:"线下用户"},{i:"3",v:"均可(线上+线下)"},{i:"4",v:"机器人"}]</script>
        <dl id="kind" class="slect"><dt>用户类型 <b class="Cf00">*</b></dt><dd><span><i class="ico">&#xe601;</i></span></dd></dl><input type="hidden" id="form_kind" name="kind">
        <dl id="crm_fromclue" class="slect"><dt>线索来源</dt><dd><span><i class="ico">&#xe601;</i></span></dd></dl><input type="hidden" id="form_crm_fromclue" name="crm_fromclue">
        <dl id="crm_ukind" class="slect"><dt>客户分类</dt><dd><span><i class="ico">&#xe601;</i></span></dd></dl><input type="hidden" id="form_crm_ukind" name="crm_ukind">
        <dl><dt>前台展示</dt><dd><span><input type="checkbox" name="flag" id="form_flag" class="switch" value="1"><label for="form_flag" class="switch-label"><i></i><b>公开</b><b>隐藏</b></label></span></dd></dl>
        <input name="submitok" type="hidden" value="addupdate" />
        <input name="t" type="hidden" value="<?php echo $t;?>" />
        <input name="uname" id="uname" type="hidden" class="input size2 W200" value="mobht_<?php echo cdnumletters(6); ?>" size="20" maxlength="20"   autocomplete="off" />
        <input name="pwd" value="<?php echo cdnumletters(6);?>" id="pwd" type="hidden" class="input size2 W200"  size="20" maxlength="20"   autocomplete="off" />
    </div>
    <script>
    Sbindbox = 'step1';
    zeai.listEach(zeai.tag(o('step1'),'dl'),function(obj){
        switch (obj.className){
            default:
                var clsName=obj.className.replace(' dl0','');
				if(!zeai.empty(clsName)){
					switch (clsName) {
						case 'ipt':kind = 'input';break;
						case 'txtarea':kind = 'textarea';break;
						case 'bthdy':kind = 'birthday';break;
						case 'slect':kind = 'select';break;
						case 'slect2':kind = 'select2';break;
						case 'rang':kind = 'range';break;
						case 'chckbox':kind = 'checkbox';break;
					}
					ZeaiM.divMod({kind:kind,obj:obj,end:function(e,i){
						o('form_'+obj.id).value=e;
					}});
				}
            break;
			case 'mob':
				mob.onclick=function(){ZeaiM.div_up({fobj:step1,obj:mob_box,h:29});};
				mob_box_btn.onclick=function(){
					if(form_mob2.value == form_mob.value && !zeai.empty(form_mob2.value)){zeai.alert('主手机号码不能和备用手机相同哦');return false;}
					zeai.ajax({url:'m_u_mod.php?submitok=ajax_user_chkmob&mob='+form_mob.value+'&mob2='+form_mob2.value},function(e){var rs=zeai.jsoneval(e);
						if (rs.flag == 1){
							var span = mob.getElementsByTagName("span")[0];
							span.html(form_mob.value);span.class('ed');
							div_up_close.click();
						}else{
							zeai.alert(rs.msg);
						}
					});
				}
			break;
        }
    });
	top_btn_save.onclick=function(){
		if(!zeai.ifmob(form_mob.value)){
			zeai.msg('请选择【手机号码】');
			return false;
		}
		if(zeai.empty(form_sex.value)){
			zeai.msg('请选择【性别】');
			return false;
		}
		if(zeai.empty(form_birthday.value)){
			zeai.msg('请选择【生日】',birthday);
			return false;
		}
		if(zeai.empty(form_nickname.value) || zeai.str_len(form_nickname.value)<2 || zeai.str_len(form_nickname.value)>40){
			zeai.msg('请输入正确的【昵称网名】(2~40字节)');
			return false;
		}
		if(zeai.empty(form_kind.value)){
			zeai.msg('请选择【用户类型】');
			return false;
		}
		if(!zeai.empty(form_identitynum.value)){
			zeai.ajax({url:'m_u_mod.php?submitok=ajax_user_chksfz&sfz='+form_identitynum.value},function(e){var rs=zeai.jsoneval(e);
				if (rs.flag == 1){
					zeai.msg('录入成功，请完善详细资料');
					setTimeout(function(){ZEAI_CN__FORM.submit();},2000);
				}else{
					zeai.alert(rs.msg);
				}
			});
		}else{
			zeai.msg('录入成功，请完善详细资料');
			setTimeout(function(){ZEAI_CN__FORM.submit();},2000);
		}
	}
    </script>
<?php }else{?>
<!--ADD END-->
<div id="step2">
<?php
/*********资料修改*********/
    $form_data=udata_arr('basic_ext');
	$form_data_num=intval(@count($form_data));$form_data_num_end=$form_data_num;
    if (is_array($form_data) && $form_data_num>0){
        $n=1;
        foreach($form_data as $F){
			$F=$F['fieldname'];
			if($F=='tag2')continue;if($F=='tag1')$F='tag';
			if($F=='tag'){
				if(!ifint($SHALOU_ARR['sex']))continue;
				$subkind = udata_title($form_data,'tag'.$SHALOU_ARR['sex'],'subkind');
				$T       = udata_title($form_data,'tag'.$SHALOU_ARR['sex']);
				
			}else{
				$subkind = udata_title($form_data,$F,'subkind');
				$T = udata_title($form_data,$F);
				
			}
            $spanid='';
			$DATA = $SHALOU_ARR[$F];
			//控件类型
            switch ($subkind) {//1:文本,2:单选,3:复选,4:区间,5:特殊
                case 1:$class='ipt';$DATA = trimhtml(dataIO($DATA,'wx'),'keep_rn');$DATA_str = $DATA;break;
                case 2:$class='slect';$DATA_str = udata($F,$DATA);break;
                case 3:$class='chckbox';
					if($F == 'tag'){
						$DATA_str = (ifint($SHALOU_ARR['sex']))?udata($F.$SHALOU_ARR['sex'],$DATA):'';
					}else{
						$DATA_str = udata($F,$DATA);
					}
				break;
				case 4:$class='slect';$DATA_str = udata($F,$DATA);break;
            }
			//控件类型-特殊
            switch ($F) {
                case 'birthday':
					$class='bthdy';$DATA_str = $DATA;
				break;
				case 'areaid':
					$class='aread';$spanid=' id="areatitle"';
					$DATA_str=(!empty($SHALOU_ARR['areatitle']))?$SHALOU_ARR['areatitle']:'';
				break;
				case 'area2id':
					$class='aread2';$spanid=' id="area2title"';
					$DATA_str=(!empty($SHALOU_ARR['area2title']))?$SHALOU_ARR['area2title']:'';
				break;
                case 'aboutus':$class='txtarea';break;
            }
			//为空默认值
			if(empty($DATA) || $DATA=='0,0' || $DATA=='0000-00-00'){
				switch ($F) {
					case 'birthday':$Y=date('Y')-23;$DATA=$Y.'-01-15';break;
					case 'edu':$DATA=getarrdef($_UDATA[$F]);break;
					case 'pay':$DATA=getarrdef($_UDATA[$F]);break;
					case 'heigh':$DATA='170';break;
					case 'weigh':$DATA='50';break;
					//default:$DATA_str = ($subkind==1)?'请输入':'请选择';break;
				}
			}
			//输出
            if($F=='photo_s'){
				$photo_s = $SHALOU_ARR[$F];
				?>
                <dl class="photo_s dlpic"><dt>头像</dt><dd id="photo_sbtn"><span>
                <?php if (!empty($photo_s)){?>
                	<img src="<?php echo UP.$photo_s;?>">
                <?php }else{ ?>
                	<i class="ico">&#xe609;</i><font class="tips">点击上传本人近期生活照</font>
                <?php }?>
                </span></dd></dl>
                <input type="hidden" name="photo_s" id="photo_s" value="<?php echo $SHALOU_ARR[$F];?>">
				<script>
                ZeaiUP.one({url:'m_u_mod'+zeai.extname,submitokBef:'ajax_tmpB_',btnobj:photo_sbtn,end:function(rs){
                    if(rs.flag==1){
						ZeaiM.div_left({obj:cut_box,w:zeai.bodyW()});
						var dbname = rs.dbname;
						photo_s.value=dbname;
						cut_tmppic.src=up2+dbname;
						www_a9a_cn_cut = new ZEAICUT(<?php echo $uid;?>);
						www_a9a_cn_cut.wake();
						www_a9a_cn_cut.init();
                    }else{
                        zeai.msg(e.msg);
                    }
                }});
                </script>
				<?php require_once ZEAI.'res/m/cut.html';?>
				<?php
			}elseif($F=='areaid'){?>
                <div id="areabox" class="areabox"><div class="ul"><li><dl><dd></dd></dl></li></div></div>
                <input type="hidden" id="form_areaid" name="areaid" value="<?php echo $SHALOU_ARR[$F];?>">
                <input type="hidden" id="form_areatitle" name="areatitle" value="<?php echo $SHALOU_ARR['areatitle'];?>"><?php
			}elseif($F=='area2id'){?>
                <div id="areabox2" class="areabox"><div class="ul"><li><dl><dd></dd></dl></li></div></div>
                <input type="hidden" id="form_area2id" name="area2id" value="<?php echo $SHALOU_ARR[$F];?>">
                <input type="hidden" id="form_area2title" name="area2title" value="<?php echo $SHALOU_ARR['area2title'];?>"><?php
            }else{?>
                <input type="hidden" id="form_<?php echo $F;?>" name="<?php echo $F;?>" value="<?php echo $DATA;?>"><?php
            }
			$dl0=($n % 8==0)?' dl0':'';
			$DATA_str = (empty($DATA_str) || $DATA_str=='0000-00-00')?'<i class="ico">&#xe601;</i>':$DATA_str;
			if($F!='photo_s')echo '<dl id="'.$F.'" class="'.$class.$dl0.'" data="'.$DATA.'"><dt>'.$T.'</dt><dd><span'.$spanid.'>'.$DATA_str.'</span></dd></dl>';
            $n++;
        }
    }
	?>
    <div class="tbody">联系方式</div>
    <?php
	//联系方式
    $form_data=udata_arr('contact');
    if (is_array($form_data) && @count($form_data)>0){
        foreach($form_data as $F){
			$F=$F['fieldname'];
			if($F=='mob')continue;
            $T = udata_title($form_data,$F);
			$DATA = $SHALOU_ARR[$F];
			if($F=='weixin_pic'){
				$weixin_pic=$DATA;
				$weixin_pic_url = (!empty($weixin_pic))?UP.$weixin_pic:RES.'photo_m.jpg';
				?>
                <dl class="photo_s dlpic"><dt><?php echo $T;?></dt><dd id="weixin_picbtn" <?php if(is_h5app()){ ?>onClick="up_wxphoto_goup()"<?php }?>><span>
                <?php if (!empty($weixin_pic)){?>
                	<img src="<?php echo $weixin_pic_url;?>">
                <?php }else{ ?>
                	<i class="ico">&#xe609;</i><font class="tips">点击上传本人<?php echo $T;?></font>
                <?php }?>
                </span></dd></dl>
                <input type="hidden" name="weixin_pic" id="weixin_pic" value="<?php echo $weixin_pic;?>">
				<script>
				ZeaiUP.one({url:'m_u_mod'+zeai.extname,submitokBef:'ajax_weixin_pic_tmp_',btnobj:weixin_picbtn,end:function(e){
                    if(e.flag==1){
                        o('weixin_picbtn').html('<span><img src="'+up2+e.dbname+'"></span>');
                        o('weixin_pic').value = e.dbname;
                    }else{
                        zeai.msg(e.msg);
                    }
                }});
                </script>
				<?php
            }else{
				$DATA_str = '请输入';
				$class='ipt';
				$DATA     = trimhtml(dataIO($DATA,'out'));
				$DATA_str = (!empty($DATA))?$DATA:'<i class="ico">&#xe601;</i>';
				echo '<dl id="'.$F.'" class="'.$class.'" data="'.$DATA.'"><dt>'.$T.'</dt><dd><span>'.$DATA_str.'</span></dd></dl>';
				echo '<input type="hidden" id="form_'.$F.'" name="'.$F.'" value="'.$DATA.'">';
			}
		}
	}
    ?>
    
    <div class="tbody">择偶要求</div>
    <div id="mate">
		<?php
		$mate_diy = explode(',',$_ZEAI['mate_diy']);
        if (count($mate_diy) >= 1 && is_array($mate_diy)){
			$n=1;
            foreach ($mate_diy as $F) {
				$ico_str='<i class="ico">&#xe601;</i>';
                $ext = mate_diy_par($F,'ext');
                switch ($ext) {
                    case 'radio':
                        $class = 'slect';
                        $D     = intval($SHALOU_ARR['mate_'.$F]);
                        $D_str = (ifint($D))?udata($F,$D):$ico_str;
                    break;
                    case 'radiorange':
                        $class  = 'rang';
                        $D1     = intval($SHALOU_ARR['mate_'.$F.'1']);
                        $D2     = intval($SHALOU_ARR['mate_'.$F.'2']);
                        $D      = $D1.','.$D2;
                        $dwarr  = json_decode($_UDATA[$F],true);$dw = $dwarr['dw'];
						$D_str  = (ifint($D1) || ifint($D2))?mateset_out($D1,$D2,$dw):$ico_str;
						$D_str  = str_replace("不限","",$D_str);
                    break;
                    case 'checkbox':
                        $class = 'chckbox';
                        $D     = $SHALOU_ARR['mate_'.$F];
                        $D_str = (!empty($D))?udata($F,$D):$ico_str;
                    break;
					default:

						switch ($F) {
							case 'areaid':
								$class='mate_aread';$spanid=' id="mate_areatitle"';
								$D   = $SHALOU_ARR['mate_'.$F];
								$D_t = $SHALOU_ARR['mate_areatitle'];
								$D_str = (!empty($D))?$D_t:$ico_str;?>
								<input type="hidden" id="form_mate_areatitle" name="form_mate_areatitle" value="<?php echo $D_t;?>">
								<?php
							break;
							case 'areaid2':
								$class='mate_aread2';$spanid=' id="mate_area2title"';
								$D   = $SHALOU_ARR['mate_'.$F];
								$D_t = $SHALOU_ARR['mate_areatitle2'];
								$D_str = (!empty($D))?$D_t:$ico_str;?>
								<input type="hidden" id="form_mate_areatitle2" name="form_mate_areatitle2" value="<?php echo $D_t;?>">
								<?php
							break;
							default:
								$spanid='';
								$D_str = (empty($D) || $D=='0,0')?'<i class="ico">&#xe601;</i>':$D;
							break;
						}
					
					break;
                }
                //默认值
                if(empty($D) || $D=='0,0'){
                    switch ($F) {
                        case 'age':$D='23,40';break;
                        case 'edu':$D=3;break;
                        case 'pay':$D=5;break;
                        case 'heigh':$D='160,175';break;
                        case 'weigh':$D='50,70';break;
                    }
                }
				$dl0='';
                echo '<dl id="mate_'.$F.'" class="'.$class.$dl0.'" data="'.$D.'"><dt>'.mate_diy_par($F).'</dt><dd><span'.$spanid.'>'.$D_str.'</span></dd></dl>';?>
                <input type="hidden" id="form_mate_<?php echo $F;?>" name="form_mate_<?php echo $F;?>" value="<?php echo $D;?>">
        <?php $n++;}}?>
        
        <dl id="mate_other" class="txtarea dl0" data="<?php echo $mate_other;?>"><dt>其他要求</dt><dd><span><?php echo $mate_other;?></span></dd></dl>
        <input type="hidden" id="form_mate_other" name="form_mate_other" value="<?php echo $mate_other;?>">
        
        
    </div>
    <?php if (in_array('areaid',$mate_diy)){?>
        <div id="mate_areabox" class="areabox"><div class="ul"><li><dl><dd></dd></dl></li></div></div>
    <?php }?>
    <?php if (in_array('areaid2',$mate_diy)){?>
        <div id="mate_areabox2" class="areabox"><div class="ul"><li><dl><dd></dd></dl></li></div></div>
    <?php }?>
</div>
	<input name="submitok" type="hidden" value="modupdate" />
	<input name="uid" type="hidden" value="<?php echo $uid;?>" />
	<input name="t" type="hidden" value="<?php echo $t;?>" />
    <script>
	Sbindbox = 'step2';
	var sex=<?php echo intval($SHALOU_ARR['sex']);?>,tag_ARR = (zeai.ifint(sex))?eval('tag'+sex+'_ARR'):tag1_ARR;
    zeai.listEach(zeai.tag(o('ZEAI_CN__FORM'),'dl'),function(obj){
		var kind='',className=obj.className.replace(' dl0','');
        switch (className){
            case 'aread':
                o('areaid').onclick=function(){
                    ZeaiM.div_up({obj:areabox,h:36});
                    ZEAI_area({areaid:o('form_areaid').value,areatitle:o('form_areatitle').value,ul:areabox.children[0],str:'job',end:function(z,e){
                        o('areatitle').html(e);o('areatitle').class('ed');
                        o('form_areaid').value=z;
                        o('form_areatitle').value=e;
                    }});
                }
            break;
            case 'aread2':
                o('area2id').onclick=function(){
                    ZeaiM.div_up({obj:areabox2,h:36});
                    ZEAI_area({areaid:o('form_area2id').value,areatitle:o('form_area2title').value,ul:areabox2.children[0],str:'hj',datastr:'hj',end:function(z,e){
                        o('area2title').html(e);o('area2title').class('ed');
                        o('form_area2id').value=z;
                        o('form_area2title').value=e;
                    }});
                }
            break;
			//择偶
            case 'mate_aread':
                o('mate_areaid').onclick=function(){
                    ZeaiM.div_up({obj:mate_areabox,h:36});
                    ZEAI_area({bx:true,areaid:o('form_mate_areaid').value,areatitle:o('form_mate_areatitle').value,ul:mate_areabox.children[0],str:'mate_job',end:function(z,e){
                        o('mate_areatitle').html(e);o('mate_areatitle').class('ed');
                        o('form_mate_areaid').value=z;
                        o('form_mate_areatitle').value=e;
                    }});
                }
            break;
            case 'mate_aread2':
                o('mate_areaid2').onclick=function(){
                    ZeaiM.div_up({obj:mate_areabox2,h:36});
                    ZEAI_area({bx:true,areaid:o('form_mate_areaid2').value,areatitle:o('form_mate_areatitle2').value,ul:mate_areabox2.children[0],str:'mate_hj',datastr:'mate_hj',end:function(z,e){
                        o('mate_area2title').html(e);o('mate_area2title').class('ed');
                        o('form_mate_areaid2').value=z;
                        o('form_mate_areatitle2').value=e;
                    }});
                }
            break;
            default:
                switch (className) {
					case 'ipt':kind = 'input';break;
					case 'txtarea':kind = 'textarea';break;
					case 'bthdy':kind = 'birthday';break;
                    case 'slect':kind = 'select';break;
                    case 'rang':kind = 'range';break;
                    case 'chckbox':kind = 'checkbox';break;
                }
				if(!zeai.empty(kind)){
					ZeaiM.divMod({kind:kind,obj:obj,end:function(e,i){
						o('form_'+obj.id).value=e;
					}});
				}
            break;
        }
    });
	top_btn_save.onclick=function(){
		zeai.ajax({url:'m_u_mod'+zeai.ajxext,form:ZEAI_CN__FORM},function(e){var rs=zeai.jsoneval(e);
			zeai.msg(0);zeai.msg(rs.msg);
			if(rs.flag==1)setTimeout(function(){location.reload(true);},1000);
		});
	}
    </script>
<?php }?>    
</form>
<?php
function udata_title($data_data,$f,$kind='') {foreach($data_data as $v){if($v['fieldname'] == $f)if($kind=='subkind'){return $v['subkind'];}else{return $v['title'];}}}
function getarrdef($arrstr) {
	$arr=json_decode($arrstr,true);
	$cout=intval(count($arr)/2)-1;
	$rt=$arr[$cout]['i'];
	return $rt;
}
function Dmod($uid,$jsonstr){
	global $db;
	$uid=intval($uid);
	$row = $db->ROW(__TBL_SHALOU__,"uid","uid=".$uid);
	if ($row){
		$db->query("UPDATE ".__TBL_SHALOU__." SET jsonstr='$jsonstr',addtime=".ADDTIME." WHERE uid=".$uid);
	}else{
		$db->query("INSERT INTO ".__TBL_SHALOU__." (uid,jsonstr,addtime) VALUES ($uid,'$jsonstr',".ADDTIME.")");
	}
}
if($t=='crm'){
	require_once 'm_crm_btm.php';
}else{
	require_once 'm_btm.php';
}
?>
